<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>login</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $("#login").click(function () {
                $.post(
                    "${pageContext.request.contextPath}/login",
                    $("#myform").serialize(),
                    function (data, status) {
                        if (data.OK === "false") {
                            alert("用户或密码错误");
                        } else if (data.OK === "true") {
                            alert("欢迎登录");
                            $(window).attr('location', '/login');
                        }
                    });
            });

            document.onkeydown = function (event) {
                var e = event || window.event;
                if (e && e.keyCode === 13) { //回车键的键值为13
                    $("#login").click(); //调用登录按钮的登录事件
                }
            };
        });


    </script>
</head>

<body>
<div class="wrap" id="wrap" align="center">
    <form id="myform">
        First name:<br>
        <input type="text" name="username">
        <br>
        Last name:<br>
        <input type="text" name="passwd">
        <p>
            <button id="login" type="button">submit</button>
        </p>
    </form>
</div>
</body>
</html>

